package com.yxinsur.imc.web.controller.business;

import java.util.HashMap;
import java.util.List;

import com.yxinsur.imc.business.domain.ImcBroker;
import com.yxinsur.imc.business.domain.ImcBrokerRole;
import com.yxinsur.imc.business.domain.ImcBrokerRoleImport;
import com.yxinsur.imc.business.excel.BrokerRoleTemplate;
import com.yxinsur.imc.business.form.BrokerRoleForm;
import com.yxinsur.imc.business.service.IImcBrokerRoleService;
import com.yxinsur.imc.business.vo.BrokerRoleVo;
import com.yxinsur.imc.common.core.domain.model.LoginUser;
import com.yxinsur.imc.common.utils.SecurityUtils;
import com.yxinsur.imc.common.utils.ServletUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yxinsur.imc.common.annotation.Log;
import com.yxinsur.imc.common.core.controller.BaseController;
import com.yxinsur.imc.common.core.domain.AjaxResult;
import com.yxinsur.imc.common.enums.BusinessType;
import com.yxinsur.imc.common.utils.poi.ExcelUtil;
import com.yxinsur.imc.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 代理人身份角色Controller
 *
 * @author imc
 * @date 2021-04-13
 */
@Api(value = "代理人职级关联接口服务",tags = {"代理人职级关联口服务"})
@RestController
@RequestMapping("/business/brokerRole")
public class ImcBrokerRoleController extends BaseController
{
    @Autowired
    private IImcBrokerRoleService imcBrokerRoleService;

    /**
     * 查询代理人职级管理列表
     */
    @ApiOperation("查询代理人职级管理列表")
    @GetMapping("/list")
    public TableDataInfo list(BrokerRoleForm brokerRoleForm)
    {
        startPage();
        List<BrokerRoleVo> list = imcBrokerRoleService.selectImcBrokerRoleList(brokerRoleForm);
        return getDataTable(list);
    }
    /**
     * 获取代理人角色信息模板
     */

    @ApiOperation(value = "获取代理人职级上传模板",produces="application/octet-stream")
    @GetMapping("/importTemplate")
    public AjaxResult importTemplate()
    {
        ExcelUtil<BrokerRoleTemplate> util = new ExcelUtil<BrokerRoleTemplate>(BrokerRoleTemplate.class);
        return util.importTemplateExcel("代理人职级导入");
    }

    @ApiOperation(value = "代理人职级信息导入")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception {
        ExcelUtil<BrokerRoleTemplate> util = new ExcelUtil<BrokerRoleTemplate>(BrokerRoleTemplate.class);
        List<BrokerRoleTemplate> brokerRoles = util.importExcel(file.getInputStream());
        String message = imcBrokerRoleService.importBrokerRole(brokerRoles);
        return AjaxResult.success(message);
    }
}
